home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hotspots / reqfiles / button.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  10.7 KB  |  314 lines  |  [TEXT/ttxt]

  1. in module DemoModule
  2.  
  3. --*******************************************************************************
  4. --*        Class name:    Button
  5. --*                                            
  6. --*     Inherits from: Actuator                                    
  7. --*        Class type: Abstract, mixin
  8. --*         Component: User Interface
  9. --*
  10. --*       Description: This is a subclass of Actuator which provides the basic
  11. --*                    protocols for pushbutton functionality.  It can be mixed
  12. --*                    in with any TwoDShape and gives it all the features of the 
  13. --*                    PushButton core class.  
  14. --*
  15. --*                    The main advantage of using this class is that it is very 
  16. --*                    light weight (it uses just one presenter) and totally 
  17. --*                    flexible in its appearance. You just have to supply the 
  18. --*                    bitmaps for its pressed, released and disabled appearances.  
  19. --*                    For even more customized appearances, you can override the
  20. --*                    setPressedAppearance, setReleasedAppearance, 
  21. --*                    setDisabledAppearance, setActivatedAppearance methods.
  22. --*                    This class can also be combined with a Rollover class to 
  23. --*                    give you a Rollover Button.
  24. --*
  25. --*             Usage: Create a new multi-inherited class
  26. --*                        class myButton (TwoDShape, Button)
  27. --*
  28. --*               IVs:    pressedBitmap
  29. --*                    releasedBitmap
  30. --*                    disabledBitmap
  31. --*                    authordata
  32. --*                    pressAction
  33. --*                    releaseAction
  34. --*                    activateAction
  35. --*                    multiActivateAction            
  36. --*
  37. --*           Methods:    handlePress
  38. --*                    handleRelease
  39. --*                    handleActivate
  40. --*                    handleMultiActivate
  41. --*                    setPressedAppearance
  42. --*                    setReleasedAppearance
  43. --*                    setDisabledAppearance
  44. --*                    setActivatedAppearance
  45. --*                    press
  46. --*                    release
  47. --*                    activate
  48. --*                    multiactivate
  49. --*                    enabledSetter
  50. --*                    init
  51. --*                    afterInit
  52. --*                    
  53. --*    Required files:    none
  54. --*                    
  55. --*             Notes: 
  56. --*
  57. --*            Author:    Su Quek - Kaleida Labs, Inc.
  58. --*******************************************************************************
  59. class Button (Actuator)
  60. inst vars
  61.     pressedBitmap
  62.     releasedBitmap
  63.     disabledBitmap
  64.     authordata
  65.     pressAction
  66.     releaseAction
  67.     activateAction
  68.     multiActivateAction
  69. end
  70.  
  71. --*=============================================================================*
  72. --*       Method name:    handlePress
  73. --*             Class:    Button
  74. --*             Usage: handlePress self
  75. --*-----------------------------------------------------------------------------*
  76. --*       Description: Calls the function specified by pressAction.
  77. --*=============================================================================*
  78. method handlePress self {class Button} ->
  79. (
  80.     if (self.pressAction != undefined) do
  81.         self.pressAction self.authordata self
  82. )
  83.  
  84. --*=============================================================================*
  85. --*       Method name:    handleRelease
  86. --*             Class:    Button
  87. --*             Usage: handleRelease self
  88. --*-----------------------------------------------------------------------------*
  89. --*       Description: Calls the function specified by releaseAction.
  90. --*=============================================================================*
  91. method handleRelease self {class Button} ->
  92. (
  93.     if (self.releaseAction != undefined) do
  94.         self.releaseAction self.authordata self
  95. )
  96.  
  97. --*=============================================================================*
  98. --*       Method name:    handleActivate
  99. --*             Class:    Button
  100. --*             Usage: handleActivate self
  101. --*-----------------------------------------------------------------------------*
  102. --*       Description: Calls the function specified by activateAction.
  103. --*=============================================================================*
  104. method handleActivate self {class Button} ->
  105. (
  106.     if (self.activateAction != undefined) do
  107.         self.activateAction self.authordata self
  108. )
  109.  
  110. --*=============================================================================*
  111. --*       Method name:    handleMultiActivate
  112. --*             Class:    Button
  113. --*             Usage: handleMultiActivate self
  114. --*-----------------------------------------------------------------------------*
  115. --*       Description: Calls the function specified by multiActivateAction.
  116. --*=============================================================================*
  117. method handleMultiActivate self {class Button} n ->
  118. (
  119.     if (self.multiActivateAction != undefined) do
  120.         self.multiActivateAction self.authordata self n
  121. )
  122.  
  123. --*=============================================================================*
  124. --*       Method name:    setPressedAppearance
  125. --*             Class:    Button
  126. --*             Usage: setPressedAppearance self
  127. --*-----------------------------------------------------------------------------*
  128. --*       Description: Change the appearance of the shape to how it will appear
  129. --*                    when the mouse is pressed within the shape's boundary.
  130. --*=============================================================================*
  131. method setPressedAppearance self {class Button} -> 
  132. (
  133.     if (self.pressedBitmap != undefined) do
  134.         self.boundary := self.pressedBitmap
  135. )
  136.  
  137. --*=============================================================================*
  138. --*       Method name:    setReleasedAppearance
  139. --*             Class:    Button
  140. --*             Usage: setReleasedAppearance self
  141. --*-----------------------------------------------------------------------------*
  142. --*       Description: Change the appearance of the shape to how it will appear
  143. --*                    when the mouse is released or moves outside the shape's 
  144. --*                    boundary.
  145. --*=============================================================================*
  146. method setReleasedAppearance self {class Button} -> 
  147. (
  148.     if (self.releasedBitmap != undefined) do
  149.         self.boundary := self.releasedBitmap
  150. )
  151.     
  152. --*=============================================================================*
  153. --*       Method name:    setDisabledAppearance
  154. --*             Class:    Button
  155. --*             Usage: setDisabledAppearance self
  156. --*-----------------------------------------------------------------------------*
  157. --*       Description: Change the appearance of the shape to how it will appear
  158. --*                    when the button is disabled.
  159. --*=============================================================================*
  160. method setDisabledAppearance self {class Button} -> 
  161. (
  162.     if (self.disabledBitmap != undefined) do
  163.         self.boundary := self.disabledBitmap
  164. )
  165.  
  166. --*=============================================================================*
  167. --*       Method name:    setActivatedAppearance
  168. --*             Class:    Button
  169. --*             Usage: setActivatedAppearance self
  170. --*-----------------------------------------------------------------------------*
  171. --*       Description: Change the appearance of the shape to how it will appear
  172. --*                    when the mouse is clicked within the shape's boundary.
  173. --*=============================================================================*
  174. method setActivatedAppearance self {class Button} -> 
  175. (
  176.     setReleasedAppearance self
  177. )
  178.  
  179. --*=============================================================================*
  180. --*       Method name:    press
  181. --*             Class:    Button
  182. --*             Usage: press self
  183. --*-----------------------------------------------------------------------------*
  184. --*       Description: Displays and executes the appropriate bitmaps and actions 
  185. --*                    when the mouse is pressed within the shape's boundary
  186. --*=============================================================================*
  187. method press self {class Button} -> 
  188. (
  189.     if not self.enabled do 
  190.         return
  191.     
  192.     nextmethod self
  193.     
  194.     setPressedAppearance self
  195.     
  196.     handlePress self
  197. )
  198.  
  199. --*=============================================================================*
  200. --*       Method name:    release
  201. --*             Class:    Button
  202. --*             Usage: release self
  203. --*-----------------------------------------------------------------------------*
  204. --*       Description: Displays and executes the appropriate bitmaps and actions 
  205. --*                    when the mouse is released or moves outside the shape's 
  206. --*                    boundary.
  207. --*=============================================================================*
  208. method release self {class Button} -> 
  209. (
  210.     if not self.enabled do 
  211.         return
  212.     
  213.     nextmethod self
  214.  
  215.     setReleasedAppearance self
  216.  
  217.     handleRelease self
  218. )
  219.  
  220. --*=============================================================================*
  221. --*       Method name:    activate
  222. --*             Class:    Button
  223. --*             Usage: activate self
  224. --*-----------------------------------------------------------------------------*
  225. --*       Description: Displays and executes the appropriate bitmaps and actions 
  226. --*                    when the mouse is clicked within the shape's boundary.
  227. --*=============================================================================*
  228. method activate self {class Button} -> 
  229. (
  230.     if not self.enabled do 
  231.         return
  232.                 
  233.     nextmethod self
  234.     
  235.     setActivatedAppearance self
  236.  
  237.     handleActivate self
  238. )
  239.  
  240. --*=============================================================================*
  241. --*       Method name:    activate
  242. --*             Class:    Button
  243. --*             Usage: activate self
  244. --*-----------------------------------------------------------------------------*
  245. --*       Description: Displays and executes the appropriate bitmaps and actions 
  246. --*                    when the mouse is clicked multiple times within the shape's 
  247. --*                    boundary.
  248. --*=============================================================================*
  249. method multiActivate self {class Button} n -> 
  250. (
  251.     if not self.enabled do 
  252.         return
  253.                 
  254.     nextmethod self n
  255.     
  256.     setActivatedAppearance self
  257.     
  258.     handleMultiActivate self n
  259. )
  260.  
  261. --*=============================================================================*
  262. --*       Method name:    enabledSetter
  263. --*             Class:    Button
  264. --*             Usage: enabledSetter self
  265. --*-----------------------------------------------------------------------------*
  266. --*       Description: Displays the appropriate bitmaps when the button is enabled
  267. --*                    or disabled.
  268. --*=============================================================================*
  269. method enabledSetter self {class Button} value ->
  270. (
  271.     nextmethod self value
  272.  
  273.     if value then
  274.         setReleasedAppearance self
  275.     else
  276.         setDisabledAppearance self
  277.     
  278.     return value
  279. )
  280.  
  281. --*=============================================================================*
  282. --*       Method name:    init
  283. --*             Class:    Button
  284. --*             Usage: init self 
  285. --*-----------------------------------------------------------------------------*
  286. --*       Description: Initializes its IVs
  287. --*=============================================================================*
  288. method init self {class Button} #rest args 
  289.                                 #key pressedBitmap:(undefined) \
  290.                                      releasedBitmap:(undefined) \
  291.                                      disabledBitmap:(undefined) ->
  292. (
  293.     apply nextmethod self args
  294.     self.pressedBitmap := pressedBitmap
  295.     self.releasedBitmap := releasedBitmap
  296.     self.disabledBitmap := disabledBitmap
  297.  
  298.     self
  299. )
  300.  
  301. --*=============================================================================*
  302. --*       Method name:    afterInit
  303. --*             Class:    Button
  304. --*             Usage: afterInit self 
  305. --*-----------------------------------------------------------------------------*
  306. --*       Description: Sets up its appearance.
  307. --*=============================================================================*
  308. method afterInit self {class Button} #rest args ->
  309. (
  310.     nextmethod self
  311.     setReleasedAppearance self
  312.     self
  313. )
  314.